#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<map>

using namespace std;

vector<int> relocateMarbles(vector<int>& nums, vector<int>& moveFrom, vector<int>& moveTo) {
    map<int, int> m;
    for (int i = 0; i < nums.size(); ++i)
        m[nums[i]]++;

    int n = moveFrom.size();
    for (int i = 0; i < n; ++i)
    {
        int f = moveFrom[i], t = moveTo[i];
        int num = m[f];
        m.erase(f);
        m[t] += num;
    }

    vector<int> res;
    for (auto it : m)
        res.push_back(it.first);
    return res;
}